package org.yxj.customlibrary.util;

import android.graphics.PointF;
import android.view.MotionEvent;

/**
 * 缩放功能相关的参数计算
 *
 * @author yxj on 2022/7/27
 */
public class ZoomViewUtil {



    /**
     * 两点间的距离
     *
     * @return
     */
    public static float distanceBetweenLength(MotionEvent event) {
        float x = event.getX(1) - event.getX(0);
        float y = event.getY(1) - event.getY(0);
        return (float) Math.sqrt(x * x + y * y);
    }



    /**
     * 两点间中心点
     *
     * @return
     */
    public static PointF distanceBetweenMiddle(MotionEvent event) {
        float x = event.getX(1) - event.getX(0);
        float y = event.getY(1) - event.getY(0);
        return new PointF(x / 2, y / 2);
    }


    /**
     * 两点产生的角度
     *
     * 取旋转角度
     * @param event
     */
    public static float distanceBetweenAngle(MotionEvent event) {
        double delta_x = (event.getX(0) - event.getX(1));
        double delta_y = (event.getY(0) - event.getY(1));
        double radians = Math.atan2(delta_y, delta_x);
        return (float) Math.toDegrees(radians);
    }

}
